package cc.mrbird.febs.buss.service.impl;

import cc.mrbird.febs.common.entity.FebsConstant;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.buss.entity.OldCard;
import cc.mrbird.febs.buss.mapper.OldCardMapper;
import cc.mrbird.febs.buss.service.IOldCardService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.beans.factory.annotation.Autowired;
import cc.mrbird.febs.common.utils.SortUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
 * 老年证申请表 Service实现
 *
 * @author jeson
 * @date 2021-04-26 11:16:54
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class OldCardServiceImpl extends ServiceImpl<OldCardMapper, OldCard> implements IOldCardService {

    /*@Autowired
    private OldCardMapper oldCardMapper;*/


    @Override
    public IPage<OldCard> findOldCardDetail(QueryRequest request, HashMap<String,String> map) {
        Page<OldCard> page = new Page<OldCard>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "id", FebsConstant.ORDER_ASC, false);
        return this.baseMapper.findOldCardDetailPageByMap(page,map);
    }

    @Override
    public List<OldCard> findOldCards(OldCard oldCard) {
	    LambdaQueryWrapper<OldCard> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public void createOldCard(OldCard oldCard) {
        this.save(oldCard);
    }

    @Override
    @Transactional
    public void updateOldCard(OldCard oldCard) {
        this.saveOrUpdate(oldCard);
    }

    @Override
    @Transactional
    public void deleteOldCard(OldCard oldCard) {
        LambdaQueryWrapper<OldCard> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}

    @Override
    @Transactional
    public void deleteOldCard(String[] ids) {
        List<String> list = Arrays.asList(ids);
        // 删除用户
        this.removeByIds(list);
    }
}
